<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller {
    public function index(){
    	echo 'Hello Admin'; 
    }
    public function userlist(){
    	//调用模型层获取数据
    $usersmodel=M('users');
     $user=$usersmodel->order('id asc')->select();
    //调用试图层显示数据
       $this->user=$user;
       $this->display();
    }
      public function deluser($id){

    $id=$_GET['id'];
    //dump($id);
    $userModel = M("users"); // 实例化User对象
    $users=$userModel->where("id=$id")->select();
    $result=$userModel->where("id=$id")->delete(); // 删除id为5的用户数据
    //dump($user);
        if ($users[0]['photo']!='nopic.jpg') {
              $oldpicPath='Public/Admin/photo/'.$users[0]['photo'];
              unlink($oldpicPath);
            }
        if($result){                    
            $this->success('删除成功');//设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
            } else {
             $this->error('删除失败'); //错误页面的默认跳转页面是返回前一页，通常不需要设置
            }
}
    public function editpswd($id){
        $usersmodel=M('users'); 
        $usersmodel->password="182131";
        if(false!==$usersmodel->where("id=$id")->save()){
            $this->success('密码重置成功!');
         }else{
             $this->error('密码重置失败!');
        }
     }
    
     public function exitLog(){
            session(null);
            redirect(U("/Admin"));
       } 
   

}